package com.xuexiang.xuidemo.page.base;

import ohos.agp.components.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * StringList
 *
 * @since 2021-03-31
 */
public abstract class StringListAbilitySlice extends SimpleTextListAbilitySlice<StringListAbilitySlice.TransfString> {
    @Override
    public void onItemClick(Component component, int position, TransfString data) {
        onItemClick(component, position, data.getName());
    }

    /**
     * Item点击事件回调
     *
     * @param component Item最外层组件
     * @param position 数据的索引位置
     * @param data 数据
     */
    public abstract void onItemClick(Component component, int position, String data);

    @Override
    protected List<TransfString> getDatas() {
        return getStringList().stream().map(TransfString::new).collect(Collectors.toList());
    }

    /**
     * 返回列表String
     *
     * @return StringArray
     */
    protected abstract List<String> getStringList();

    /**
     * String转SimpleText内部类
     *
     * @since 2021-03-31
     */
    public static class TransfString implements SimpleTextListAbilitySlice.SimpleText {
        private final String name;

        private TransfString(String name) {
            this.name = name;
        }

        @Override
        public String getName() {
            return name;
        }
    }
}
